<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.0.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.16.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"width":300},"copycode":{"enable":true,"style":"mac"},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="环境  centos:7.9 docker:1.13.1 mongo:latest安装docker和docker-compose123456# 1.使用yum安装dockeryum install -y docker# 2.安装epel第三方软件包(Extra Packages for Enterprise Linux)yum install -y epel-release# 3.安装docker">
<meta property="og:type" content="article">
<meta property="og:title" content="使用Docker安装Mongo">
<meta property="og:url" content="http://example.com/2021/06/10/%E4%BD%BF%E7%94%A8Docker%E5%AE%89%E8%A3%85Mongo/index.html">
<meta property="og:site_name" content="lxb的个人博客">
<meta property="og:description" content="环境  centos:7.9 docker:1.13.1 mongo:latest安装docker和docker-compose123456# 1.使用yum安装dockeryum install -y docker# 2.安装epel第三方软件包(Extra Packages for Enterprise Linux)yum install -y epel-release# 3.安装docker">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-06-10T07:00:00.000Z">
<meta property="article:modified_time" content="2023-05-06T11:20:22.008Z">
<meta property="article:author" content="lxb">
<meta property="article:tag" content="运维">
<meta property="article:tag" content="部署">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://example.com/2021/06/10/%E4%BD%BF%E7%94%A8Docker%E5%AE%89%E8%A3%85Mongo/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2021/06/10/%E4%BD%BF%E7%94%A8Docker%E5%AE%89%E8%A3%85Mongo/","path":"2021/06/10/使用Docker安装Mongo/","title":"使用Docker安装Mongo"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>使用Docker安装Mongo | lxb的个人博客</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="lxb的个人博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">lxb的个人博客</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%89%E8%A3%85docker%E5%92%8Cdocker-compose"><span class="nav-number">1.</span> <span class="nav-text">安装docker和docker-compose</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8docker%E7%BC%96%E6%8E%92%E5%AE%89%E8%A3%85mongo"><span class="nav-number">2.</span> <span class="nav-text">使用docker编排安装mongo</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#compose%E5%86%85%E5%AE%B9"><span class="nav-number">2.1.</span> <span class="nav-text">compose内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%91%BD%E4%BB%A4"><span class="nav-number">2.2.</span> <span class="nav-text">命令</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%98%B2%E7%81%AB%E5%A2%99%E7%AB%AF%E5%8F%A3"><span class="nav-number">3.</span> <span class="nav-text">防火墙端口</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%A3%80%E6%9F%A5-mongodb-%E6%98%AF%E5%90%A6%E8%BF%90%E8%A1%8C%E6%AD%A3%E5%B8%B8"><span class="nav-number">4.</span> <span class="nav-text">检查 mongodb 是否运行正常</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="lxb"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">lxb</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">6</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    

    
    
    
      <div id="music163player">
        <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width= 330 height=110 src="//music.163.com/outchain/player?type=0&id=387263893&auto=0&height=90"></iframe>
      </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/06/10/%E4%BD%BF%E7%94%A8Docker%E5%AE%89%E8%A3%85Mongo/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="lxb">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="lxb的个人博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="使用Docker安装Mongo | lxb的个人博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          使用Docker安装Mongo
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-06-10 15:00:00" itemprop="dateCreated datePublished" datetime="2021-06-10T15:00:00+08:00">2021-06-10</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-05-06 19:20:22" itemprop="dateModified" datetime="2023-05-06T19:20:22+08:00">2023-05-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E8%BF%90%E7%BB%B4/" itemprop="url" rel="index"><span itemprop="name">运维</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>环境</p>
<ul>
<li>centos:7.9</li>
<li>docker:1.13.1</li>
<li>mongo:latest<h1 id="安装docker和docker-compose"><a href="#安装docker和docker-compose" class="headerlink" title="安装docker和docker-compose"></a>安装docker和docker-compose</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># 1.使用yum安装docker</span><br><span class="line">yum install -y docker</span><br><span class="line"># 2.安装epel第三方软件包(Extra Packages for Enterprise Linux)</span><br><span class="line">yum install -y epel-release</span><br><span class="line"># 3.安装docker编排</span><br><span class="line">yum install -y docker-compose</span><br></pre></td></tr></table></figure>
<span id="more"></span>
<h1 id="使用docker编排安装mongo"><a href="#使用docker编排安装mongo" class="headerlink" title="使用docker编排安装mongo"></a>使用docker编排安装mongo</h1><h2 id="compose内容"><a href="#compose内容" class="headerlink" title="compose内容"></a>compose内容</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">mongodb:</span><br><span class="line">    image: docker.io/mongo</span><br><span class="line">    container_name: mongodb</span><br><span class="line">    restart: always</span><br><span class="line">    volumes:</span><br><span class="line">      - /etc/localtime:/etc/localtime:ro</span><br><span class="line">      - ./data/mongo/db:/data/db</span><br><span class="line">      - ./data/mongo/log:/var/log/mongodb</span><br><span class="line">    ports:</span><br><span class="line">      - 27017:27017</span><br><span class="line">    environment:</span><br><span class="line">      - MONGO_INITDB_ROOT_USERNAME=admin</span><br><span class="line">      - MONGO_INITDB_ROOT_PASSWORD=admin</span><br><span class="line">      - TZ=Asia/Shanghai</span><br><span class="line">    privileged: true</span><br></pre></td></tr></table></figure>
<h2 id="命令"><a href="#命令" class="headerlink" title="命令"></a>命令</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># -d 参数为后台执行</span><br><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure>
<h1 id="防火墙端口"><a href="#防火墙端口" class="headerlink" title="防火墙端口"></a>防火墙端口</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># 1.查看当前开启的端口</span><br><span class="line">firewall-cmd --zone=public --list-ports --permanent</span><br><span class="line"># 2.添加开放永久端口</span><br><span class="line">firewall-cmd --zone=public --add-port=27017/tcp --permanent</span><br><span class="line"># 3.重新加载配置</span><br><span class="line">firewall-cmd --reload</span><br></pre></td></tr></table></figure>
<h1 id="检查-mongodb-是否运行正常"><a href="#检查-mongodb-是否运行正常" class="headerlink" title="检查 mongodb 是否运行正常"></a>检查 mongodb 是否运行正常</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># 1.查看容器运行情况</span><br><span class="line">docker ps</span><br><span class="line"># 2.容器日志查看</span><br><span class="line">docker logs mongo</span><br><span class="line">docker logs -f mongodb 持续打印</span><br><span class="line">docker logs -f --tail 100 mongodb 打印末端100行</span><br><span class="line">docker logs --tail 100 mongodb &gt; mongodb.log 输出日志到当前mongodb.log文件中</span><br></pre></td></tr></table></figure></li>
</ul>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E8%BF%90%E7%BB%B4/" rel="tag"># 运维</a>
              <a href="/tags/%E9%83%A8%E7%BD%B2/" rel="tag"># 部署</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/06/10/%E4%BD%BF%E7%94%A8Docker%E5%AE%89%E8%A3%85Mysql80/" rel="prev" title="使用 Docker 安装 Mysql80">
                  <i class="fa fa-chevron-left"></i> 使用 Docker 安装 Mysql80
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/06/10/%E4%BD%BF%E7%94%A8Docker%E5%AE%89%E8%A3%85Redis/" rel="next" title="使用 Docker 安装 Redis">
                  使用 Docker 安装 Redis <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lxb</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>






  





</body>
</html>
